import { PushAction } from '../actions'
import { PicType } from '../Types'
import { 
  GetPushList_PENDING, 
  GetPushList_FULFILLED,
  GetPushList_Type } from '../Constants'
// 初始化
const initState= {
  loading: false,
  record: {},
  list: [],
  type: 1,
}
export function PushReducer(state: PicType = initState, action: PushAction): PicType {
  switch (action.type) {
    case GetPushList_PENDING:
      return { ...state, loading: true }
    case GetPushList_Type:
      return { ...state, type: action.payload }
    case GetPushList_FULFILLED:
      let list = state.list
      if (state.type == 1) list = action.payload.list
      else list = [
        ...state.list||[],
        ...action.payload.list
      ]
      return { 
        ...state, 
        loading: false, 
        list
      }
  }
  return state
}